//
//  APIHeatRateDelegateProxy.swift
//  APIHeartRate_Example
//
//  Created by Tek on 2023/1/5.
//  Copyright © 2023 CocoaPods. All rights reserved.
//

import Foundation
public enum DeviceBleStatus {
    case connecting
    case connected
    case disconnecting
    case disconnected
}
public enum BatteryStatus {
    case normal
    case charging
    case full
    case unknown
}
public enum DeviceMode {
    case daily
    case sport
}
public enum ModeType {
    case other
    case autoIn
    case autoOut
}
public enum HeartRateMode: UInt8 {
    case autoDynamic = 0x01
    case autoStatic = 0x02
    case forceDynamic = 0x03
}
public enum WearStatus {
    case loosen
    case overTime
}
public enum ScenarioType {
    case lesson
    case quickWalk
    case daily
    
    static func mapTypeFrom(value: UInt8) -> ScenarioType {
        switch value {
        case 0x00:
            return .lesson
        case 0x01:
            return .quickWalk
        default:
            return .daily
        }
    }
}
public struct FBKApiBaseInfo {}
public struct HRInfo {
    public let time: String
    public let rateStr: String
    init(rate: Int) {
        time = HRInfo.getTimeStr()
        rateStr = String(rate)
    }

    internal static let dateFormatter: DateFormatter = {
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-mm-dd HH:mm:ss"
        formatter.locale = Locale.init(identifier: "en_US_POSIX")
        return formatter
    }()

    static func getTimeStr() -> String {
        let stringWithDate = dateFormatter.string(from: Date())
        return stringWithDate
    }
}

public protocol APIHeartRateObserver {
    func devicePower(power: String, device: BleDevice)
    func deviceFirmware(version: String, device: BleDevice)
    func deviceHardware(version: String, device: BleDevice)
    func deviceSoftware(version: String, device: BleDevice)
    func privateVersion(version: [String: String], device: BleDevice)
    func privateMacAddress(mac: String, device: BleDevice)
    func deviceSystemData(systemData: Data, device: BleDevice)
    func deviceModelString(modelString: String, device: BleDevice)
    func deviceSerialNumber(serialNumer: String, device: BleDevice)
    func deviceManufacturerName(manufacturerName: String, device: BleDevice)
    func deviceBaseInfo(baseInfo: FBKApiBaseInfo, device: BleDevice)
    func HRVResultData(hrvMap: [String: String], device: BleDevice)
    func armBandStepFrequency(frequencyDic: [String: String], device: BleDevice)
    func armBandTemperature(tempMap: [String: String], device: BleDevice)
    func armBandSPO2(spo2Map: [String: String], device: BleDevice)
    func armBandRealTimeHeartRate(hRInfo: HRInfo, device: BleDevice)
    func armBandMaxHeartRateUpdated()
    func armBandSystemTimeUpdated()
    func armBandBloodOxygen(num: Int, device: BleDevice)
    func armBandPlayStatusChange()
    func armBandResetFactory(isTimeOut: Bool)
    func armBandUnbind()
    func batteryStatus(state: BatteryStatus)
    func heartRateInMeasuring()
    func armBandModeChanged(mode: DeviceMode, type: ModeType)
    func armBandRealTimePressure(pressure: Int, device: BleDevice)
    

    func bleConnectLog(logString: String, device: BleDevice?)
    func bleConnectStatus(status: DeviceBleStatus, device: BleDevice?)
    func bleConnectError(error: BleConnectError, device: BleDevice?)
    func didDiscoveryWith(devices: [BleDicoveryDevice])
    func didFinishDiscoveryWith(devices: [BleDicoveryDevice])
    func bleCommonError(error: BleCommonError)
    func bleAvailability(status: BleAvailability)
    
    func bleOtaError(error: OtaError)
    func bleOtaStauts(status: OtaStatus, progress: Float)
    
    func summaryHeartRateInfo(info: [[String: Any]], isBusy: Bool)
    func summaryStepsInfo(info: [[String: Any]], isBusy: Bool)
    func summaryBloodOxygenInfo(info: [[String: Any]], isBusy: Bool)
    func summaryPressureIndexInfo(info: [[String:Any]], isBusy: Bool)
    func summaryCalorieInfo(info: [[String:Any]], isBusy: Bool)
    func summarySleepInfo(info: [[String:Any]], isBusy: Bool)
    func summaryExerciseInfo(info: [[String:Any]], isBusy: Bool)
    func motionDataInfo(info:[[String:Any]], isSport: Bool, isBusy: Bool)
    func motionDataSeqUpdated(isSport: Bool)
    func currentBandTime(timeNow: Double)
    func sportModeDetailInfo(info: [String: Int], isBusy: Bool)
    func doNotDisturbTimeInfo(enabled: Bool)
    func exitedSleepAlgorithm()
    func lightStatusChanged(on: Bool)
    func heartRateModeChange(mode: HeartRateMode)
    func gymnasticModeChanged(on: Bool)
    
    func rawDataLog(type: FetchDataType,log: String)
    func heartRateMockStatus(on: Bool)
    func wearingStatus(status: WearStatus)
    func deviceInformation(info: [String: Any])
    func scenarioChanged(type: ScenarioType)
    func cursorInformation(info: [String:Int])
}

public extension APIHeartRateObserver {
    func devicePower(power: String, device: BleDevice) {}
    func deviceFirmware(version: String, device: BleDevice) {}
    func deviceHardware(version: String, device: BleDevice) {}
    func deviceSoftware(version: String, device: BleDevice) {}
    func privateVersion(version: [String: String], device: BleDevice) {}
    func privateMacAddress(mac: String, device: BleDevice) {}
    func deviceSystemData(systemData: Data, device: BleDevice) {}
    func deviceModelString(modelString: String, device: BleDevice) {}
    func deviceSerialNumber(serialNumer: String, device: BleDevice) {}
    func deviceManufacturerName(manufacturerName: String, device: BleDevice) {}
    func deviceBaseInfo(baseInfo: FBKApiBaseInfo, device: BleDevice) {}
    func HRVResultData(hrvMap: [String: String], device: BleDevice) {}
    func armBandStepFrequency(frequencyDic: [String: String], device: BleDevice) {}
    func armBandTemperature(tempMap: [String: String], device: BleDevice) {}
    func armBandSPO2(spo2Map: [String: String], device: BleDevice) {}
    func armBandRealTimeHeartRate(hRInfo: HRInfo, device: BleDevice) {}
    func armBandMaxHeartRateUpdated() {}
    func armBandSystemTimeUpdated() {}
    func armBandBloodOxygen(num: Int, device: BleDevice) {}
    func armBandPlayStatusChange() {}
    func armBandResetFactory(isTimeOut: Bool) {}
    func armBandUnbind() {}
    func batteryStatus(state: BatteryStatus) {}
    func heartRateInMeasuring() {}
    func armBandModeChanged(mode: DeviceMode, type: ModeType) {}
    func armBandRealTimePressure(pressure: Int, device: BleDevice) {}

    func bleConnectLog(logString: String, device: BleDevice?) {}
    func bleConnectStatus(status: DeviceBleStatus, device: BleDevice?) {}
    func bleConnectError(error: BleConnectError, device: BleDevice?) {}
    func didDiscoveryWith(devices: [BleDicoveryDevice]) {}
    func didFinishDiscoveryWith(devices: [BleDicoveryDevice]) {}
    func bleCommonError(error: BleCommonError) {}
    func bleAvailability(status: BleAvailability) {}
    
    func bleOtaError(error: OtaError) {}
    func bleOtaStauts(status: OtaStatus, progress: Float) {}
   
    func summaryHeartRateInfo(info: [[String: Any]], isBusy: Bool) {}
    func summaryStepsInfo(info: [[String: Any]], isBusy: Bool) {}
    func summaryBloodOxygenInfo(info: [[String: Any]], isBusy: Bool) {}
    func summaryPressureIndexInfo(info: [[String:Any]], isBusy: Bool) {}
    func summaryCalorieInfo(info: [[String:Any]], isBusy: Bool) {}
    func summarySleepInfo(info: [[String:Any]], isBusy: Bool) {}
    func summaryExerciseInfo(info: [[String:Any]], isBusy: Bool) {}
    func motionDataInfo(info:[[String:Any]], isSport: Bool, isBusy: Bool) {}
    func motionDataSeqUpdated(isSport: Bool) {}
    func currentBandTime(timeNow: Double) {}
    func sportModeDetailInfo(info: [String: Int], isBusy: Bool) {}
    func disturbModeChange(on: Bool) {}
    func doNotDisturbTimeInfo(enabled: Bool) {}
    func exitedSleepAlgorithm() {}
    func lightStatusChanged(on: Bool) {}
    func heartRateModeChange(mode: HeartRateMode) {}
    func gymnasticModeChanged(on: Bool) {}
    func rawDataLog(type: FetchDataType, log: String) {}
    func heartRateMockStatus(on: Bool) {}
    func wearingStatus(status: WearStatus) {}
    func deviceInformation(info: [String: Any]) {}    
    func scenarioChanged(type: ScenarioType) {}
    func cursorInformation(info: [String:Int]) {}
}

